package org.weasel.wizards;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;


public class BasicProjectPage extends WizardPage {
	private Text projectNameText;
	@SuppressWarnings("unused")
	private ISelection selection;

	public BasicProjectPage(ISelection selection) {
		super("wizardPage");
		setTitle("Create a project");
        setDescription("Create a project in the workspace.");
        try {
			setImageDescriptor(ImageDescriptor.createFromURL(new URL("file:icons/proj_wiz.gif")));
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        this.selection = selection;
        setPageComplete(false);
	}
	
	public void createControl(Composite parent) {
		{
			parent.setSize(525, 223);
		}
		// TODO Auto-generated method stub
		Composite container = new Composite(parent, SWT.NULL);
        GridLayout layout = new GridLayout();
        container.setLayout(layout);
        layout.numColumns = 2;
        layout.verticalSpacing = 9;

        Label label = new Label(container, SWT.NULL);
        label.setText("Project name:");

        projectNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        projectNameText.setLayoutData(gd);
        projectNameText.addModifyListener(new ModifyListener() {
                public void modifyText(ModifyEvent e) {
                    dialogChanged();
                }
            });
        setControl(container);
    }

    private void dialogChanged() {
        if (getProjectName().length() == 0) {
            updateStatus("Project name must be specified.");
            return;
        }
        updateStatus(null);
    }

    private void updateStatus(String message) {
        setErrorMessage(message);
        setPageComplete(message == null);
    }
    
    public String getProjectName() {
    	return projectNameText.getText();
    }
}

